package jehc.cloud.gen.web;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jehc.cloud.common.annotation.NeedLoginUnAuth;
import jehc.cloud.common.base.BasePage;
import jehc.cloud.common.base.BaseResult;
import jehc.cloud.common.base.BaseSearch;
import jehc.cloud.common.util.StringUtil;
import jehc.cloud.gen.base.BaseAction;
import jehc.cloud.gen.model.XtUrlConfig;
import jehc.cloud.gen.service.XtUrlConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @Desc 地址配置
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@RestController
@RequestMapping("/xtUrlConfig")
@Api(value = "地址配置API",description = "地址配置API")
public class XtUrlConfigController extends BaseAction {

    @Autowired
    private XtUrlConfigService xtUrlConfigService;

    /**
     * 列表页面
     * @param model
     * @return
     */
    @ApiOperation(value="列表页面", notes="列表页面")
    @RequestMapping(value="/pageList")
    public ModelAndView pageList(Model model) {
        return new ModelAndView("xt-url-config/xt-url-config-list");
    }

    /**
     * 新增页面
     * @param model
     * @return
     */
    @ApiOperation(value="新增页面", notes="新增页面")
    @RequestMapping(value="/pageAdd")
    public ModelAndView pageAdd(Model model) {
        return new ModelAndView("xt-url-config/xt-url-config-add");
    }

    /**
     * 编辑页面
     * @param model
     * @param xt_url_config_id
     * @return
     */
    @ApiOperation(value="编辑页面", notes="编辑页面")
    @RequestMapping(value="/pageUpdate")
    public ModelAndView pageUpdate(Model model,String xt_url_config_id) {
        model.addAttribute("xt_url_config_id",xt_url_config_id);
        return new ModelAndView("xt-url-config/xt-url-config-update");
    }

    /**
     * 详情页面
     * @param model
     * @param xt_url_config_id
     * @return
     */
    @ApiOperation(value="详情页面", notes="详情页面")
    @RequestMapping(value="/pageDetail")
    public ModelAndView pageDetail(Model model,String xt_url_config_id) {
        model.addAttribute("xt_url_config_id",xt_url_config_id);
        return new ModelAndView("xt-url-config/xt-url-config-detail");
    }

    /**
     * 分页查询
     * @param baseSearch
     */
    @NeedLoginUnAuth
    @PostMapping(value="/list")
    @ApiOperation(value="分页查询", notes="分页查询")
    @ResponseBody
    public BasePage getXtUrlConfigListByCondition(@RequestBody(required=true)BaseSearch baseSearch){
        Map<String, Object> condition = baseSearch.convert();
        commonPager(condition,baseSearch);
        List<XtUrlConfig> xtUrlConfigList = xtUrlConfigService.getXtUrlConfigListByCondition(condition);
        PageInfo<XtUrlConfig> page = new PageInfo<XtUrlConfig>(xtUrlConfigList);
        return outPageBootStr(page,baseSearch);
    }

    /**
     * 全部集合
     */
    @NeedLoginUnAuth
    @GetMapping(value="/listAll")
    @ApiOperation(value="全部集合", notes="全部集合")
    @ResponseBody
    public BaseResult listAll(){
        Map<String, Object> condition = new HashMap<>();
        List<XtUrlConfig> xtUrlConfigList = xtUrlConfigService.getXtUrlConfigListByCondition(condition);
        return outComboDataStr(xtUrlConfigList);
    }

    /**
     * 单条记录
     * @param xt_url_config_id
     */
    @NeedLoginUnAuth
    @GetMapping(value="/get/{xt_url_config_id}")
    @ApiOperation(value="查询单个信息", notes="查询单个")
    @ResponseBody
    public BaseResult getXtUrlConfigById(@PathVariable("xt_url_config_id")String xt_url_config_id){
        XtUrlConfig xtUrlConfig = xtUrlConfigService.getXtUrlConfigById(xt_url_config_id);
        return outDataStr(xtUrlConfig);
    }

    /**
     * 添加
     * @param xtUrlConfig
     * @return
     */
    @PostMapping(value="/add")
    @ApiOperation(value="添加一个地址配置", notes="添加一个地址配置")
    @ResponseBody
    public BaseResult addXtUrlConfig(@RequestBody XtUrlConfig xtUrlConfig){
        int i = 0;
        if(null != xtUrlConfig){
            xtUrlConfig.setXt_url_config_id(toUUID());
            i=xtUrlConfigService.addXtUrlConfig(xtUrlConfig);
        }
        if(i>0){
            return outAudStr(true);
        }else{
            return outAudStr(false);
        }
    }
    /**
     * 修改
     * @param xtUrlConfig
     */
    @PutMapping(value="/update")
    @ApiOperation(value="编辑单个信息", notes="编辑单个信息")
    @ResponseBody
    public BaseResult updateXtDbinfo(@RequestBody XtUrlConfig xtUrlConfig){
        int i = 0;
        if(null != xtUrlConfig){
            i=xtUrlConfigService.updateXtUrlConfig(xtUrlConfig);
        }
        if(i>0){
            return outAudStr(true);
        }else{
            return outAudStr(false);
        }
    }
    /**
     * 删除
     * @param xt_url_config_id
     */
    @DeleteMapping(value="/delete")
    @ApiOperation(value="删除信息", notes="删除信息")
    @ResponseBody
    public BaseResult delXtUrlConfig(String xt_url_config_id){
        int i = 0;
        if(!StringUtil.isEmpty(xt_url_config_id)){
            Map<String, Object> condition = new HashMap<String, Object>();
            condition.put("xt_url_config_id",xt_url_config_id.split(","));
            i=xtUrlConfigService.delXtUrlConfig(condition);
        }
        if(i>0){
            return outAudStr(true);
        }else{
            return outAudStr(false);
        }
    }
}
